package ink.xiaobaibai.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import ink.xiaobaibai.entity.Coupon;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author xiaobaibai
 * @since 2021-06-05
 */
public interface CouponDao extends BaseMapper<Coupon> {

    @Select("SELECT c.* FROM coupon c WHERE c.`id` NOT IN((SELECT coupon_id FROM coupon_user WHERE `user_id`=#{userId})) AND stop_use=0 AND deadline > NOW()")
    public List<Coupon> getCanReceiveCouponByUserId(@Param("userId") Integer userId);

}
